﻿#pragma once
#include "AutoReleaseRunable.h"

#include "BaseMsg.h"

#include "TLV.h"


#include <QMutex>



class TcpConnectHandler : public AutoReleaseRunable
{
public:
	TcpConnectHandler(SOCKET connection);

	virtual ~TcpConnectHandler();

	virtual int start();


	static void initSocket();

	//socket 消息收发接口
	int readMsgType(SString &msgType);

	int readNextTlv(TLV *& tlv);

	int readMagNum();

	BaseMsg * readMsg();

	int sendMsg(BaseMsg * msg);

    int handleReportStatusReq(BaseMsg * req);

    int handleComputerAlarmReq(BaseMsg *req);


public:
	static TcpConnectHandler* connect(SString ip, int port);

    static TcpConnectHandler* connect(SString ip, int port, int connectTimeOut);


public:
	

	SOCKET connection;

	bool connectionIsGood = true;

	static long connnectionCount;

    static QMutex *connectionCountLock;

    SString remoteIP;

    int remotePort;


};

